package com.huawei.appmarket.service.alarm.control;

import android.content.Context;
import android.os.Bundle;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appmarket.service.predownload.jobservice.UrgentUpdateJobService;
import com.huawei.appmarket.service.predownload.jobservice.WlanPeriodicJobService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.cdb;
import o.cdg;
import o.cgd;
import o.cuh;
import o.Logger;
import o.doo;
import o.dpn;
import o.dps;
import o.dqa;
import o.dqd;
import o.dqe;
import o.dqg;
import o.dqn;
import o.dqp;
import o.dqs;
import o.dss;
import o.dvt;
import o.dwx;
import o.dxb;
import o.eaz;
import o.edk;
import o.edl;
import o.edx;
import o.eny;
import o.CollectCheck;
import o.euc;
import o.euf;

public class HiAppNetworkChangeService extends BaseNetworkStateChangeService {
    public void executeNetworkStateChangeTask() {
        Context applicationContext = getApplicationContext();
        if (doo.ˊ(applicationContext)) {
            if (!dss.ॱ().ʻॱ()) {
                euc.ˊ().ॱ();
                ॱ();
                euc.ˊ().ˏ();
            }
            cuh.ˋ(applicationContext);
            WlanPeriodicJobService.schedule();
            UrgentUpdateJobService.schedule();
            return;
        }
        Logger.ˎ("HiAppNetworkChangeService", "network is not connected");
    }

    private void ॱ() {
        List arrayList = new ArrayList();
        ˎ(arrayList);
        ˊ(arrayList);
        ˋ(arrayList);
        if (ˎ()) {
            if (hasAutoReserveDldTasks()) {
                arrayList.add(dqp.class);
            }
            if (dqe.ˋ()) {
                arrayList.add(dqe.class);
                if (ˊ()) {
                    Logger.ˎ("HiAppNetworkChangeService", "can not execute PreDlManagerTask, because download failed for many times!");
                    ((edx) cdb.ॱ(edx.class)).ˎ();
                } else {
                    arrayList.add(dqn.class);
                }
            } else {
                ॱ(arrayList);
            }
            ˏ(arrayList);
        }
        if (arrayList.isEmpty()) {
            Logger.ˏ("HiAppNetworkChangeService", "no task to run");
            return;
        }
        Class[] clsArr = (Class[]) arrayList.toArray(new Class[arrayList.size()]);
        Bundle bundle = new Bundle();
        bundle.putInt(RepeatingTaskManager.KEY_PRE_DOWNLOAD_START_TYPE, 12);
        RepeatingTaskManager.execute(getApplicationContext(), bundle, clsArr);
    }

    private boolean ˊ() {
        if (edl.ˏ().ˈ() <= 0) {
            return false;
        }
        List<ApkUpgradeInfo> ˎ = dss.ॱ().ˎ(true, 1);
        if (ˎ.isEmpty()) {
            return false;
        }
        boolean z;
        for (ApkUpgradeInfo ᐝ : ˎ) {
            int ˊ = edk.ˏ().ˊ(ᐝ.ᐝ());
            if (ˊ != -1) {
                if (ˊ < edl.ˏ().ˈ()) {
                }
            }
            z = false;
        }
        z = true;
        return z;
    }

    private void ˎ(List<Class<? extends dpn>> list) {
        if (UserSession.getInstance().isLoginSuccessful() && !eaz.ˏ().ॱ().isEmpty()) {
            list.add(dqg.class);
        }
    }

    private void ˊ(List<Class<? extends dpn>> list) {
        if (UserSession.getInstance().isLoginSuccessful() && !cgd.ˎ().ˏ().isEmpty()) {
            list.add(dqa.class);
        }
    }

    private void ॱ(List<Class<? extends dpn>> list) {
        if (dss.ॱ().ˋ(true, 1) > 0 && dss.ॱ().ˎ() && !dqn.ᐝ()) {
            if (ˊ()) {
                Logger.ˎ("HiAppNetworkChangeService", "can not execute PreDlManagerTask, because download failed for many times!");
                ((edx) cdb.ॱ(edx.class)).ˎ();
                return;
            }
            list.add(dqn.class);
        }
    }

    private void ˋ(List<Class<? extends dpn>> list) {
        if (dwx.ˋ().ॱ().size() != 0) {
            list.add(dxb.class);
        }
    }

    private boolean ˎ() {
        return doo.ॱॱ(getApplicationContext()) && !doo.ᐝ(getApplicationContext());
    }

    private void ˏ(List<Class<? extends dpn>> list) {
        if (UserSession.getInstance().isLoginSuccessful()) {
            ʽ(list);
            ʼ(list);
            ʻ(list);
        }
    }

    private void ʽ(List<Class<? extends dpn>> list) {
        if (((cdg) cdb.ॱ(cdg.class)).ˊ() > 0) {
            list.add(dqd.class);
        }
    }

    private void ʼ(List<Class<? extends dpn>> list) {
        if (eny.ˊ().ˋ().size() > 0) {
            list.add(dqs.class);
        }
    }

    private void ʻ(List<Class<? extends dpn>> list) {
        if (euf.ˎ().ˋ()) {
            Collection ˎ = dps.ˎ();
            if (!CollectCheck.isEmpty(ˎ)) {
                list.addAll(ˎ);
            }
        }
    }

    public boolean hasAutoReserveDldTasks() {
        if (dvt.ˏ().ʻ() && !dvt.ˏ().ˎ()) {
            return true;
        }
        Logger.ˏ("HiAppNetworkChangeService", "no auto reserve dld task");
        return false;
    }
}
